package com.terrynoya.fight.stateMachine.controllers
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.combat.Explod;
	import com.terrynoya.fight.combat.ExplodData;
	import com.terrynoya.fight.emuns.PositionType;
	import com.terrynoya.fight.evaluation.Node;
	import com.terrynoya.fight.stateMachine.StateController;
	import com.terrynoya.fight.util.Misc;
	import com.terrynoya.geom.MVector2D;
	
	public class ExplodCtrl extends StateController
	{
		private var _animationId:int;
		private var _velocity:MVector2D;
		private var _acceleration:MVector2D;
		private var _posType:int;
		private var _removeTime:int;
		
		public function ExplodCtrl(name:String)
		{
			super(name);
		}
		
		override public function build():void
		{
			this._animationId = this.getAttributeAsInt("anim");
			this._posType = Misc.getPositionType(this.getAttribute("postype"));
			this._removeTime = this.getAttributeAsInt("removetime");
		}
		
		override public function run(character:Character):void
		{
			var data:ExplodData = this.createExplodData(character);
			var explod:Explod = new Explod(character.engine,data);
			explod.engine.addEntity(explod);
		}
		
//		private function getPos(character:Character):MVector2D
//		{
//			var vec:MVector2D = new MVector2D(); 
//			var arr:Array = this.stateSystem.buildFullExpression("pos");
//			if(arr.length >= 1)
//			{
//				var nodeX:Node = arr[0];
//				vec.x = nodeX.excute(character);
//			}
//			else if(arr.length == 2)
//			{
//				var nodeY:Node = arr[1];
//				vec.y = nodeY.excute(character);
//			}
//			return vec;
//		}
		
		private function createExplodData(character:Character):ExplodData
		{
			var data:ExplodData = new ExplodData();
			data.position = this.transAttrToVec("pos",character);
			data.animationId = this._animationId;
			data.positionType = this._posType;
			data.creator = character;
			data.offsetor = data.positionType == PositionType.P2 ? character.getOpponent() : character;
			if(this.hasAttribute("removetime"))
			{
				data.removeTime = this._removeTime;
			}
			else
			{
				data.removeTime = -2;
			}
			return data;
		}
	}
}